#ifndef THREADPOOL_WIN_H
#define THREADPOOL_WIN_H

#include <process.h>
#include <Windows.h>

struct Job
{
	unsigned int(__stdcall *callback_func)(void * param);
	void * param;
	struct Job * next;
	Job()
	{
		callback_func = NULL;
		param = NULL; 
		next = NULL;
	}
};

struct ThreadPool
{
	int thread_num;
	int queue_max_num;
	struct Job * head;
	struct Job * tail;
	HANDLE * hThreads;
	CRITICAL_SECTION cs;
	CONDITION_VARIABLE cv_empty;
	CONDITION_VARIABLE cv_not_full;
	CONDITION_VARIABLE cv_not_empty;
	int queue_cur_num;
	int queue_close;
	int pool_close;
};

struct ThreadPool * threadpool_init(int thread_max_num, int queue_max_num);

int threadpool_add_job(struct ThreadPool * pool, unsigned int (__stdcall *callback_func)(void *), void * param);

int threadpool_destroy(struct ThreadPool * pool);

unsigned int __stdcall threadpool_func(void * param);





#endif 
